package com.khshop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.khshop.mapper.LoginfoMapper;
import com.khshop.pojo.Loginfo;
import com.khshop.service.LoginfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.khshop.vo.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * <p>
 * 访问日志 服务实现类
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-16
 */
@Service
public class LoginfoServiceImpl extends ServiceImpl<LoginfoMapper, Loginfo> implements LoginfoService {


    @Autowired(required = false)
    LoginfoMapper loginfoMapper;

    //新增访问日志
    public ServiceResult<Loginfo> addLogInfo(Loginfo loginfo){
        return ServiceResult.of(loginfoMapper.insert(loginfo)>0);

    }

    //修改访问日志
//    public ServiceResult<Loginfo> updateLogInfo(Loginfo loginfo){
//        return ServiceResult.of(loginfoMapper.updateById(loginfo)>0);
//
//    }

    //删除访问日志
    public ServiceResult<Loginfo> delLogInfo(Integer id){
        return ServiceResult.of(loginfoMapper.deleteById(id)>0);

    }


    //查询访问日志
    public ServiceResult<IPage<Loginfo>> searchLogInfo(Map<String,String> map, Integer page, Integer limit){
        QueryWrapper<Loginfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.allEq(map);
        Page<Loginfo> iPage = new Page<Loginfo>(page, limit);
        IPage<Loginfo> orderIPage = loginfoMapper.selectPage(iPage, queryWrapper);
        return ServiceResult.of(orderIPage,orderIPage.getSize()>0);

    }
}
